package org.lds.hotkey.console.business.hotkey.controller;

import lombok.extern.slf4j.Slf4j;
import org.lds.hotkey.common.model.dto.ResultDTO;
import org.lds.hotkey.common.model.pojo.OrderBy;
import org.lds.hotkey.common.model.pojo.PageResult;
import org.lds.hotkey.console.business.hotkey.model.request.*;
import org.lds.hotkey.console.business.hotkey.model.response.*;
import org.lds.hotkey.console.business.hotkey.service.HotKeyBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *  基础前端控制器
 *
 * @author lidongsheng
 * @since 2024-06-18
 */
@Slf4j
@RestController
@RequestMapping("/api/common/hotkey")
public class HotKeyBaseController {

    @Autowired
    private HotKeyBaseService hotKeyBaseService;

    /**
    * 创建
    */
    @PostMapping("/create")
    public ResultDTO<HotKeyBaseResponse> createHotKey(@RequestBody @Validated HotKeyBaseCreateRequest request) {
         return hotKeyBaseService.createHotKey(request); 
    }
 
    /**
    * 批量创建
    */
    @PostMapping("/batch-create")
    ResultDTO<HotKeyBaseBatchCreateResponse> batchCreateHotKey(@RequestBody @Validated HotKeyBaseBatchCreateRequest request) {
        return hotKeyBaseService.batchCreateHotKey(request);
    }

    /**
    * 删除
    */
    @PostMapping("/delete")
    ResultDTO<HotKeyBaseDeleteResponse> deleteHotKey(@RequestBody HotKeyBaseDeleteRequest request) {
        return hotKeyBaseService.deleteHotKey(request);
    }

    /**
    * 批量删除
    */
    @PostMapping("/batch-delete")
    ResultDTO<HotKeyBaseBatchDeleteResponse> batchDeleteHotKey(@RequestBody @Validated HotKeyBaseBatchDeleteRequest request) {
        return hotKeyBaseService.batchDeleteHotKey(request);
    }

    /**
    * 更新
    */
    @PostMapping("/update")
    ResultDTO<HotKeyBaseResponse> updateHotKey(@RequestBody @Validated HotKeyBaseUpdateRequest request) {
        return hotKeyBaseService.updateHotKey(request);
    }

    /**
    * 批量更新
    */
    @PostMapping("/batch-update")
    ResultDTO<HotKeyBaseBatchUpdateResponse> batchUpdateHotKey(@RequestBody @Validated HotKeyBaseBatchUpdateRequest request) {
        return hotKeyBaseService.batchUpdateHotKey(request);
    }

    /**
    * 查询
    */
    @PostMapping("/list")
    ResultDTO<HotKeyBaseListResponse> listHotKey(@RequestBody HotKeyBaseListRequest request) {
        return hotKeyBaseService.listHotKey(request);
    }

    /**
    * 查询所有
    */
    @PostMapping("/list-all")
    ResultDTO<HotKeyBaseListResponse> listAllHotKey(@RequestBody OrderBy orderBy) {
        return hotKeyBaseService.listAllHotKey(orderBy);
    }

    /**
    * 根据ID查询
    */
    @PostMapping("/get")
    ResultDTO<HotKeyBaseResponse> getHotKeyById(@RequestBody @Validated HotKeyBaseGetByIdRequest request) {
        return hotKeyBaseService.getHotKeyById(request);
    }

    /**
    * 根据ID集合查询
    */
    @PostMapping("/gets")
    ResultDTO<HotKeyBaseListResponse> getHotKeyByIds(@RequestBody @Validated HotKeyBaseGetByIdsRequest request) {
        return hotKeyBaseService.getHotKeyByIds(request);
    }
                                        
    /**
    * 分页查询
    */
    @PostMapping("/list-page")
    ResultDTO<PageResult<HotKeyBaseResponse>> listHotKeyPage(@RequestBody HotKeyBaseListPageRequest request) {
        return hotKeyBaseService.listHotKeyPage(request);
    }

    /**
    * 业务主键对应数据是否存在
    */
    @PostMapping("/isExist")
    public ResultDTO<Boolean> isExist(@RequestBody @Validated HotKeyBaseGetByKeyRequest request) {
        return ResultDTO.success(hotKeyBaseService.getHotKeyByKey(request) != null);
    }

    /**
    * 异步批量创建 - 慎用(并发不高可以无脑使用)
    */
    @PostMapping("/batch-create-async")
    ResultDTO<HotKeyBaseBatchCreateResponse> batchCreateHotKeyAsync(@RequestBody @Validated HotKeyBaseBatchCreateRequest request) {
        return hotKeyBaseService.batchCreateHotKeyAsync(request);
    }

    /**
    * 异步批量删除 - 慎用(并发不高可以无脑使用)
    */
    @PostMapping("/batch-delete-async")
    ResultDTO<HotKeyBaseBatchDeleteResponse> batchDeleteHotKeyAsync(@RequestBody @Validated HotKeyBaseBatchDeleteRequest request) {
        return hotKeyBaseService.batchDeleteHotKeyAsync(request);
    }

    /**
    * 异步批量更新 - 慎用(并发不高可以无脑使用)
    */
    @PostMapping("/batch-update-async")
    ResultDTO<HotKeyBaseBatchUpdateResponse> batchUpdateHotKeyAsync(@RequestBody @Validated HotKeyBaseBatchUpdateRequest request) {
        return hotKeyBaseService.batchUpdateHotKeyAsync(request);
    }
           
}